<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Grade extends Model
{
    //
    protected $fillable = ['name', 'sort'];

    public $timestamps = false;

    public function games(){
        return $this->hasMany(Game::class);
    }
    public function histories(){
        return $this->hasMany(History::class);
    }
    public function deviceGrades(){
        return $this->hasMany(DeviceGrade::class);
    }
    public function devices(){
        return $this->belongsToMany(Device::class, 'device_grades');
    }
    public static function getArr(){
        $data = self::orderBy('sort')->orderBy('sort')->get();
        if (empty($data)){
            return $data;
        }
        $result = [];
        foreach ($data as $v){
            $result[$v['id']] = $v['name'];
        }
        return $result;
    }
}
